
package cassandrawindow;

/**
 * @author ADMIN
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.sql.Time;
import java.util.*;
import java.util.ArrayList;
/**
 *
 * @author ADMIN
 */
public class MysqlDataManagerDW {

    private Connection conn = null;
    private String TABLE_BANNERS                = "ox_banners";
    private String V3_DOMAIN_DATE_VMASK         = "v3_domain_date_vmask";
    private String V3_BAN_DATE_VMASK            = "v3_domain_date_vmask";
    private String V3_DOMAIN_DATE               = "v3_domain_date";//V3_DOMAIN_DATE
    
    public MysqlDataManagerDW()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(ACCOUNT.URL_MYSQL_MAIN , ACCOUNT.username_mysql_main, ACCOUNT.pass_mysql_main);//abc!@#
            //Debug.println("Connected to MySQL GFS Server database");
        }
        catch (Exception ex)
        {
            Debug.println("Couldn't connect to the MySQL database.  Make sure the MySQL connector jar is in the lib directory.  See the installation documentation for more information. ");
            Debug.println(ex.getMessage());
            Debug.println(ex.getMessage());
        }
        /* try {
            ConnectionPool connPool = new ConnectionPool(ACCOUNT.URL_MYSQL_MAIN, ACCOUNT.username_mysql_main, ACCOUNT.pass_mysql_main);
            conn = connPool.getConnection();
            Debug.println("Connected to MySQL Server 6.7 database");

        } catch (SQLException ex) {
            ex.printStackTrace();
            Debug.println("Couldn't connect to the MySQL database 6.7.  Make sure the MySQL connector jar is in the lib directory.  See the installation documentation for more information. ");
            Debug.println(ex.getMessage());
            Debug.println(ex.getMessage());
        }*/
    }

    public void shutdownConnection()
    {
        try {
            conn.close();
            conn = null;
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    
    public Map getUvUcByCampaignid(String date)
    {
        Map<Integer, String> uv_uc = new HashMap<>();

        try
        {
            Statement st= (Statement)conn.createStatement();
            ResultSet rs = st.executeQuery("SELECT campaignid,uc,uv FROM vmask_cpc_campaign_uv_uc where dt ='"+date+"'");
            //Debug.println("SELECT campaignid,uc,uv FROM cpc_cam_date_uniq");
            while (rs.next())
            {
                uv_uc.put(rs.getInt("campaignid"), rs.getString("uc")+"_"+rs.getString("uv"));
            }
            rs.close();
            st.close();
        }
        catch (Exception ex)
        {
            Debug.println(ex.getMessage());
            Debug.println("Couldn't connect to the MySQL database 6.7. ");
        }

        return uv_uc;
    }

    public Map getUvUcByBannerid(String date)
    {
        Map<Integer, String> uv_uc = new HashMap<>();

        try
        {
            Statement st= (Statement)conn.createStatement();
            ResultSet rs = st.executeQuery("SELECT bannerid,uc,uv FROM vmask_cpc_banner_uv_uc where dt ='"+date+"'");
            //Debug.println("SELECT bannerid,uc,uv FROM cpc_ban_date_uniq");
            while (rs.next())
            {
                uv_uc.put(rs.getInt("bannerid"), rs.getString("uc")+"_"+rs.getString("uv"));
            }
            rs.close();
            st.close();
        }
        catch (Exception ex)
        {
            Debug.println(ex.getMessage());
            Debug.println("Couldn't connect to the MySQL database 6.7. ");
        }

        return uv_uc;
    }
}
